import { useState } from "react"
import { upload } from "./upload";

function useFileUpload() {
    const open = () => {
        const input = document.createElement('input');
        input.type = 'file'
        input.onchange = function (res) {
            Object.keys(input.files).forEach(key=>{
                // upload({
                //    url: 'https://boss-api-test.hiphopservice.com/file/upload',
                // }).then(res=>{
                //    console.log('uoload',res) 
                // })
                  files.push({
                    file:input.files[key],
                    url:'',
                    name:input.files[key].name,
                    uid:Math.random()
                  })
            })
            // console.log('res', input.files)
            setFiles([...files])
        }
        input.click()
    }
    const [files, setFiles] = useState([]);
    return {
        open,
        files
    }
}
export default useFileUpload